package com.github.baichuan.application.scaffold.rest.dto.resource;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.github.baichuan.application.scaffold.rest.domain.authorization.Resource;
import com.github.baichuan.mapping.Mapping;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.util.LinkedList;
import java.util.List;

@Schema(title = "功能菜单")
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TreeNode {
    @Schema(title = "菜单Id")
    @Mapping
    private String id;

    @Schema(title = "菜单Id")
    @Mapping("parent.id")
    private String parentId;

    @Schema(title ="菜单功能名称")
    @Mapping
    private String name;

    @Schema(title ="图标样式")
    @Mapping
    private String icon;

    @Schema(title ="权限代码")
    @Mapping
    private String code;

    @Schema(title = "资源类型")
    @Mapping
    private Resource.Kind kind;

    @Schema(title = "资源类型名称")
    @Mapping("kind")
    private String kindName;

    @Schema(title = "前端路由")
    @Mapping
    private String route;

    @Schema(title = "前端路径")
    @Mapping
    private String path;

    @Schema(title = "菜单排序")
    @Mapping
    private Integer sort;

    @Schema(title = "子菜单")
    private List<TreeNode> children;

    public void appendChild(TreeNode child){
        if(children == null){
            children = new LinkedList<>();
        }
        children.add(child);
    }
}
